#include <BackgroundSubtractor/median.h>

BackgroundSubtractorMedian::BackgroundSubtractorMedian(int capacity, const cv::Scalar& threshold)
:generator(BackgroundImageGeneratorMedian(capacity)),subtractor(BackgroundSubtractorRGBThresh(threshold)){
}

BackgroundSubtractorMedian::~BackgroundSubtractorMedian(){
}

BackgroundSubtractorMedian::BackgroundSubtractorMedian(const BackgroundSubtractorMedian& other)
:generator(BackgroundImageGeneratorMedian()),subtractor(BackgroundSubtractorRGBThresh()){
	*this=other;
}

const BackgroundSubtractorMedian& BackgroundSubtractorMedian::operator=(const BackgroundSubtractorMedian& other){
	this->generator=other.generator;
	this->subtractor=other.subtractor;
	return *this;
}

void BackgroundSubtractorMedian::apply(const cv::Mat& src, cv::Mat& dst){
	generator.generate(src,temp);
	subtractor.setBGImage(temp);
	subtractor.apply(src,dst);
}

void BackgroundSubtractorMedian::update(const cv::Mat& src){
	generator.update(src);
}

void BackgroundSubtractorMedian::train(const std::vector<cv::Mat>& trainingset){
	for(std::vector<cv::Mat>::const_iterator it=trainingset.begin(); it!= trainingset.end(); it++)
		update(*it);
}
